package com.jushu.storbox.entities;

import java.io.File;

import android.content.ContentValues;
import android.database.Cursor;

import com.jushu.storbox.database.IBaseDao;
import com.jushu.storbox.database.IObjectConvert;

/**
 * if the file backup success then </br>
 * create this object and insert to database
 */
public class AlbumFileInfo implements IObjectConvert {

	private String parent;
	
	private String filePath;
	
    private String fileName;
    
    private String ownerBy;
    
    private String md5;
    
    private Long fileSize;
    
    private Long clientMtime;
    
    private int status;
    
    private File realFile = null;

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getOwnerBy() {
		return ownerBy;
	}

	public void setOwnerBy(String ownerBy) {
		this.ownerBy = ownerBy;
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public Long getFileSize() {
		return fileSize;
	}

	public void setFileSize(Long fileSize) {
		this.fileSize = fileSize;
	}

	public Long getClientMtime() {
		return clientMtime;
	}

	public void setClientMtime(Long clientMtime) {
		this.clientMtime = clientMtime;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getParent() {
		return parent;
	}

	public void setParent(String parent) {
		this.parent = parent;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	@Override
	public void fromCursor(Cursor cursor) {
		setParent(cursor.getString(cursor.getColumnIndex(IBaseDao.parent_folder_id)));
		setFileName(cursor.getString(cursor.getColumnIndex(IBaseDao.file_name)));
		setOwnerBy(cursor.getString(cursor.getColumnIndex(IBaseDao.owner_by)));
		setMd5(cursor.getString(cursor.getColumnIndex(IBaseDao.file_md5)));
		setFileSize(cursor.getLong(cursor.getColumnIndex(IBaseDao.file_size)));
		setStatus(cursor.getInt(cursor.getColumnIndex(IBaseDao.status)));
		setClientMtime(cursor.getLong(cursor.getColumnIndex(IBaseDao.client_mtime)));
		setFilePath(cursor.getString(cursor.getColumnIndex(IBaseDao.local_path)));
	}

	@Override
	public ContentValues toContentValues() {
		ContentValues cv = new ContentValues();
		cv.put(IBaseDao.file_name, getFileName());
		cv.put(IBaseDao.owner_by, getOwnerBy());
		cv.put(IBaseDao.file_md5, getMd5());//
		cv.put(IBaseDao.file_size, getFileSize());
		cv.put(IBaseDao.status, getStatus());
		cv.put(IBaseDao.client_mtime, getClientMtime());
		cv.put(IBaseDao.parent_folder_id, getParent());
		cv.put(IBaseDao.local_path, getFilePath());
		return cv;
	}
    
	public ContentValues getStatusCV() {
		ContentValues cv = new ContentValues();
		cv.put(IBaseDao.status, getStatus());
		return cv;
	}

	public boolean exists() {
		if(realFile == null) {
			realFile = new File(filePath);
		}
		return realFile.exists();
	}
}
